class Solution {
public:
    int uniquePaths(int m, int n)
    {
        vector<vector<int>> memo(m, vector<int>(n, -1));
        function<int(int, int)> dfs = [&](int i, int j) {
            int& res = memo[i][j];
            if (res != -1) return res;
            if (i == -1 || j == -1) return res = 0;
            if (i == 0 || j == 0) return res = 1;
            return res = dfs(i - 1, j) + dfs(i, j - 1);
            };
        return dfs(m - 1, n - 1);
    }
};